import pandas as pd
import numpy as np
from sklearn.cluster import KMeans, DBSCAN  # 引入KMeans


# arr = np.array([5, 10, 11, 13, 15, 35, 50, 55, 72, 92, 204, 215])
arr = np.mat(pd.read_csv("F:/成信大/多元统计分析/text.csv", header=None))
# arr = np.mat(pd.read_csv("F:/成信大/多元统计分析/test3-2.csv", header=None))
k = 3

# print(pd.cut(arr, k))
# print(pd.value_counts(pd.cut(arr, k)))
kms = KMeans(n_clusters=k)
kms.fit(arr)
kms.fit_transform(arr)
kms.fit_predict(arr)
y = kms.fit_predict(arr)
# y = DBSCAN(eps=0.5, min_samples=k).fit(arr)
print("A:", arr[(kms.labels_ == 2)])
print("B:", arr[(kms.labels_ == 0)])
print("C:", arr[(kms.labels_ == 1)])


